package com.atguigu.classroom.user.service.impl;

import com.atguigu.classroom.model.user.UserInfo;
import com.atguigu.classroom.user.mapper.UserInfoMapper;
import com.atguigu.classroom.user.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2022-07-17
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Override
    public List<UserInfo> getByIds(List<Long> ids) {
        return userInfoMapper.selectBatchIds(ids);
    }

    @Override
    public void saveUserInfo(UserInfo userInfo) {
        LambdaQueryWrapper<UserInfo> userInfoQueryWrapper=new LambdaQueryWrapper<>();
        userInfoQueryWrapper.eq(UserInfo::getOpenId,userInfo.getOpenId());
        List<UserInfo> userInfos = userInfoMapper.selectList(userInfoQueryWrapper);
        //sql-1:根据OpenId查看数据库中是否有此用户信息
        if(userInfos.size()==0){
            userInfoMapper.insert(userInfo);//sql-2:插入数据
        }
    }
}
